<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // document.cookie
            // setCookie(); 增改一体;
            // getCookie(); 获取;
            // removeCookie(); 删除;0
            // path 
            // domain 


        // setCookie ；增，改一体
        function setCookie( name , value , expires ){
            // 核心 : 操作字符串 !;
            var cookie_str = name + "=" + value;
            // 判断要不要增加 过期时间；
            if(typeof expires === "number"){
                var d = new Date();
                d.setDate(d.getDate() + expires);
                cookie_str += ";expires=" + d;
            }
            // 拼好的字符串写到 document.cookie 上;
            document.cookie = cookie_str;
        }
        // getCookie ；获取，查询 
        function getCookie( name ){
            // 分割;
            // 一定要以分号加空格的间隔进行分割;
            var cookie_arr = document.cookie.split("; ");
            for(var i = 0; i<cookie_arr.length; i++){

                var cookie_item = cookie_arr[i]
                cookie_item = cookie_item.split("=");
                
                if(cookie_item[0] == name){
                    return cookie_item[1];
                }
            }
            return "";
        }

        // 删除 Cookie ；
        function removCookie( name ){
            setCookie( name , "" , -1);
        }
    </script>
</body>
</html>